Environment

1 Dimension Overview

Radial plot, what is covered and what is not.

2 Maps

LULC

Code
pacman::p_load(
  mapview,
  dplyr,
  sf,
  viridisLite,
  stars
)

# Have to pull this from sm-data
# atlas <- readRDS('data/sm_data.rds')[['atlas']]

LULC Change

Land Use Diversity

Code
pacman::p_load(
  mapview,
  dplyr,
  sf,
  viridisLite,
  stars
)

# Have to pull this from sm-data
# atlas <- readRDS('data/sm_data.rds')[['atlas']]

VT Biodiversity Project

The next couple of maps are not only ancient, but can’t easily be aggregated at the county level. I’m all ears if folks know if better datasets out there that cover biodiversity across New England.

Species Atlas

Code
pacman::p_load(
  mapview,
  dplyr,
  sf,
  viridisLite
)

atlas <- readRDS('data/sm_data.rds')[['atlas']]
get_str(atlas)
Classes 'sf' and 'data.frame':  255 obs. of  15 variables:
 $ OBJECTID  : int  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2..
 $ TOWNNAME  : chr  "CANAAN" "FRANKLIN" "BERKSHIRE" "HIGHGATE" "RICHFORD" "SW"..
 $ PLANT     : int  9 29 18 21 0 25 3 14 7 4 6 0 15 10 0 7 5 4 5 0 4 1 2 4 44 ..
 $ BRYOP     : int  0 6 0 0 3 0 0 0 0 0 15 0 3 2 0 2 0 1 0 0 0 0 0 0 0 1 0 1 0..
 $ FERN      : int  0 7 5 1 10 5 0 9 6 1 4 0 3 3 0 15 1 1 1 0 6 2 1 6 1 3 6 4 ..
 $ TREE      : int  5 0 9 18 10 0 9 10 9 9 8 7 14 14 0 16 8 4 10 0 16 0 14 12 ..
 $ HERP      : int  1 7 3 25 6 16 16 4 12 6 7 5 3 5 3 1 4 10 7 0 6 8 1 2 15 6 ..
 $ MAMML     : int  7 12 3 3 2 6 5 5 2 5 8 5 8 4 1 4 2 2 3 2 5 2 3 12 10 4 5 6..
 $ FISH      : int  4 0 13 6 8 3 0 0 0 0 4 19 0 0 0 5 0 0 0 0 0 0 0 0 0 13 0 1..
 $ BEARK_F   : int  10 0 4 -999999 25 -999999 -999999 26 4 12 33 10 13 10 -999..
 $ BEARK_M   : int  14 1 5 -999999 24 -999999 -999999 13 7 30 36 13 4 4 -99999..
 $ MOOSEMOR  : int  29 -999999 -999999 -999999 -999999 1 -999999 34 23 1 5 2 9..
 $ SHAPESTAre: num  86286665 106010613 108619321 154926055 111999651 159764358..
 $ SHAPESTLen: num  63060 42590 41948 57511 42429 68325 56006 43724 39884 4081..
 $ geometry  :sfc_POLYGON of length 255; first list element: List of 1
  ..$ : num [1:477, 1:2] 569255 570322 571339 572315 573112 573695 574314 5749..
  ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA N..
  ..- attr(*, "names")= chr [1:14] "OBJECTID" "TOWNNAME" "PLANT" "BRYOP" "FER"..
Code
atlas <- atlas %>% 
  rename(
    TOWN = TOWNNAME,
    BRYOPHYTE = BRYOP,
    MAMMAL = MAMML
  ) %>% 
  mutate(
    TOTAL_SPP = rowSums(across(c(
      PLANT, BRYOPHYTE, FERN, TREE, HERP, MAMMAL, FISH
    )))
  )
    
mapview(
  atlas,
  zcol = 'TOTAL_SPP',
  layer.name = 'Species Richness',
  label = 'TOWN'
)

Species Atlas

Biodiversity Hotspots

Code
pacman::p_load(
  dplyr,
  sf,
  mapview
)

hotspots <- readRDS('data/sm_data.rds')[['hotspots']]

mapview(hotspots)

Biodiversity Hotspots Map

Forest Biomass

3 Metadata Table

Using the table:

  • Click column headers to sort
  • Global search in the top right, or column search in each header
  • Change page length and page through results at the bottom
  • Use the download button to download a .csv file of the filtered table
  • Click the arrow on the left of each row for details, including a URL to the data source.
Code
pacman::p_load(
  dplyr,
  reactable,
  stringr,
  htmltools
)

# Load full metadata table
metadata_all <- readRDS('data/sm_data.rds')[['metadata']]

# Pick out variables to display
metadata <- metadata_all %>% 
  select(
    metric,
    'Variable Name' = variable_name,
    definition,
    dimension,
    index,
    indicator,
    units,
    'Year' = latest_year, # Renaming latest year as year, not including og year
    source,
    scope,
    resolution,
    url
) %>% 
  setNames(c(str_to_title(names(.))))

###
htmltools::browsable(
  tagList(
    
    tags$div(
      style = "display: flex; gap: 16px; margin-bottom: 20px; justify-content: center;",
      
      tags$button(
        class = "btn btn-primary",
        style = "display: flex; align-items: center; gap: 8px; padding: 8px 12px;",
        tagList(fontawesome::fa("download"), "Show/hide more columns"),
        onclick = "Reactable.setHiddenColumns('metadata_table', prevColumns => {
          return prevColumns.length === 0 ? ['Definition', 'Scope', 'Resolution', 'Url'] : []
        })"
      ),
      
      tags$button(
        class = "btn btn-primary",
        style = "display: flex; align-items: center; gap: 8px; padding: 8px 12px;",
        tagList(fontawesome::fa("download"), "Download as CSV"),
        onclick = "Reactable.downloadDataCSV('metadata_table', 'sustainability_metadata.csv')"
      )
    ),
    
    reactable(
      metadata,
      sortable = TRUE,
      resizable = TRUE,
      filterable = TRUE,
      searchable = TRUE,
      pagination = TRUE,
      bordered = TRUE,
      wrap = TRUE,
      rownames = FALSE,
      onClick = 'select',
      striped = TRUE,
      pageSizeOptions = c(5, 10, 25, 50, 100),
      defaultPageSize = 5,
      showPageSizeOptions = TRUE,
      highlight = TRUE,
      style = list(fontSize = "14px"),
      compact = TRUE,
      columns = list(
        Metric = colDef(
          minWidth = 200,
          sticky = 'left'
        ),
        'Variable Name' = colDef(
          minWidth = 150
        ),
        Definition = colDef(
          minWidth = 250
        ),
        'Latest Year' = colDef(minWidth = 75),
        Source = colDef(minWidth = 250),
        Scope = colDef(show = FALSE),
        Resolution = colDef(show = FALSE),
        Url = colDef(
          minWidth = 300,
          show = FALSE
        )
      ),
      defaultColDef = colDef(minWidth = 100),
      elementId = "metadata_table",
      details = function(index) {
        div(
          style = "padding: 15px; border: 1px solid #ddd; margin: 10px 0;
             background-color: #E0EEEE; border-radius: 10px; border-color: black;
             box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);",
          
          tags$h4(
            strong("Details"), 
          ),
          tags$p(
            strong('Metric Name: '), 
            as.character(metadata_all[index, 'metric']),
          ),
          tags$p(
            strong('Variable Name: '), 
            as.character(metadata_all[index, 'variable_name']),
          ),
          tags$p(
            strong('Definition: '), 
            as.character(metadata_all[index, 'definition']),
          ),
          tags$p(
            strong('Source: '), 
            as.character(metadata_all[index, 'source'])
          ),
          tags$p(
            strong('Latest Year: '), 
            as.character(metadata_all[index, 'latest_year'])
          ),
          tags$p(
            strong('All Years (cleaned, wrangled, and included): '), 
            as.character(metadata_all[index, 'year'])
          ),
          tags$p(
            strong('Updates: '), 
            str_to_title(as.character(metadata_all[index, 'updates']))
          ),
          tags$p(
            strong('URL: '), 
            tags$a(
              href = as.character(metadata_all[index, 'url']),
              target = '_blank',
              as.character(metadata_all[index, 'url'])
            )
          )
        )
      }
    )
  )
)

4 Data Table

Code
pacman::p_load(
  dplyr,
  reactable,
  stringr,
  htmltools
)

# Load metrics and metadata
metadata_all <- readRDS('data/sm_data.rds')[['metadata']]
metrics <- readRDS('data/sm_data.rds')[['metrics']]
fips_key <- readRDS('data/sm_data.rds')[['fips_key']]

# Value formatting function based on units
source('dev/format_values.R')

# Filter to economics metrics, join with metadata and county fips codes
env_metrics <- metrics %>% 
  left_join(metadata_all, by = join_by('variable_name')) %>% 
  filter(dimension == 'economics') %>% 
  left_join(fips_key, by = join_by('fips')) %>% 
  mutate(county_name = ifelse(is.na(county_name), state_name, county_name)) %>% 
  format_values() %>% 
  select(
    metric,
    'Variable Name' = variable_name,
    definition,
    year = year.x,
    Area = county_name,
    units,
    value
  ) %>% 
  setNames(c(str_to_title(names(.)))) %>% 
  filter(!is.na(Value))


## Reactable table
htmltools::browsable(
  tagList(
    
    tags$div(
      style = "display: flex; gap: 16px; margin-bottom: 20px; justify-content: center;",
      tags$button(
        class = "btn btn-primary",
        style = "display: flex; align-items: center; gap: 8px; padding: 8px 12px;",
        tagList(fontawesome::fa("download"), "Download as CSV"),
        onclick = "Reactable.downloadDataCSV('metrics_table', 'sustainability_metrics.csv')"
      )
    ),
    
    reactable(
      env_metrics,
      sortable = TRUE,
      resizable = TRUE,
      filterable = TRUE,
      searchable = TRUE,
      pagination = TRUE,
      bordered = TRUE,
      wrap = TRUE,
      rownames = FALSE,
      onClick = 'select',
      striped = TRUE,
      pageSizeOptions = c(5, 10, 25, 50, 100),
      defaultPageSize = 5,
      showPageSizeOptions = TRUE,
      highlight = TRUE,
      style = list(fontSize = "14px"),
      compact = TRUE,
      columns = list(
        Metric = colDef(
          minWidth = 125,
          sticky = 'left'
        ),
        'Variable Name' = colDef(
          minWidth = 125
        ),
        Definition = colDef(
          minWidth = 250
        ),
        Units = colDef(minWidth = 100),
        'Year' = colDef(minWidth = 100)
      ),
      defaultColDef = colDef(minWidth = 100),
      elementId = "metrics_table"
    )
  )
)

5 Bivariate Plots

6 Correlations

7 PCA

Back to top